<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  // 1-5的和
  // fn(5) = 5 + 4 + 3 + 2 + 1;   fn(5) = 5 + fn(4);
  // fn(4) = 4 + 3 + 2 + 1;       fn(4) = 4 + fn(3); 
  // fn(3) = 3 + 2 + 1;           fn(3) = 3 + fn(2); 
  // fn(2) = 2 + 1;               fn(2) = 2 + fn(1);
  // fn(1) = 1;                   fn(1) = 1;

  // fn(n) = n + fn(n-1);  
  // fn(1) = 1;

  // 依赖性递归  => 有规律的重复性操作( 一个数的结果 依赖于前一个或多个数的结果)
  function fn(i) {
    if (i == 1) {
      return 1;
    }
    return i + fn(i - 1);
  }

  // fn(5) => 5 + fn(4) => 4 + fn(3) => 3 + fn(2) => 2 + fn(1)
  //                                                       ||
  //  15  <=  5  + 10  <=  4  +  6  <=  3  +  3  <=   2 +  1 

  var sum = fn(100);
  console.log(sum);







</script>

</html>